﻿using Microsoft.EntityFrameworkCore;

namespace Devonline.AspNetCore;

/// <summary>
/// 附加信息类服务
/// 每个 TEntitySet 类型中的 TAdditional 类型的附加信息认为有且仅有一个
/// </summary>
/// <typeparam name="TDbContext">数据库上下文</typeparam>
/// <typeparam name="TEntitySet">业务数据类型</typeparam>
/// <typeparam name="TAdditional">附加信息数据类型</typeparam>
/// <typeparam name="TViewModel">业务数据对象视图类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
public interface IDataModelWithAdditionalService<TDbContext, TEntitySet, TAdditional, TViewModel, TKey> :
    IDataWithAdditionalService<TDbContext, TEntitySet, TAdditional, TKey>,
    IDataModelService<TDbContext, TEntitySet, TViewModel, TKey>
    where TDbContext : DbContext
    where TEntitySet : class, IEntitySet<TKey>
    where TAdditional : class, IAdditional<TKey>
    where TViewModel : class, IViewModel<TKey>
    where TKey : IConvertible
{
    /// <summary>
    /// 新增业务数据的附加信息
    /// </summary>
    /// <typeparam name="TModel">业务数据类型</typeparam>
    /// <param name="model">业务数据</param>
    /// <param name="additionals">附加数据集合</param>
    /// <returns></returns>
    Task AddAdditionalsAsync<TModel>(TModel model, IEnumerable<TAdditional> additionals) where TModel : class, IEntitySet<TKey>;
    /// <summary>
    /// 更新业务数据的附加信息
    /// </summary>
    /// <typeparam name="TModel">业务数据类型</typeparam>
    /// <param name="model">业务数据</param>
    /// <param name="additionals">附加数据集合</param>
    /// <param name="isLogical">是否逻辑操作, 默认不是</param>
    /// <returns></returns>
    Task UpdateAdditionalsAsync<TModel>(TModel model, IEnumerable<TAdditional> additionals, bool isLogical = false) where TModel : class, IEntitySet<TKey>;
}

/// <summary>
/// 字符串作为主键的附加信息类服务
/// 每个 TEntitySet 类型中的 TAdditional 类型的附加信息认为有且仅有一个
/// </summary>
/// <typeparam name="TDbContext">数据库上下文</typeparam>
/// <typeparam name="TEntitySet">业务数据类型</typeparam>
/// <typeparam name="TAdditional">附加信息数据类型</typeparam>
public interface IDataModelWithAdditionalService<TDbContext, TEntitySet, TAdditional> :
    IDataModelWithAdditionalService<TDbContext, TEntitySet, TAdditional, string>,
    IDataService<TDbContext, TEntitySet>
    where TDbContext : DbContext
    where TEntitySet : class, IEntitySet
    where TAdditional : class, IAdditional
{ }